#! /bin/sh /usr/share/dpatch/dpatch-run
## 82_6602_ringbuffer_reset.dpatch by  <root@mythserver.home.rodriguez-vudoyra.com>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
diff -urNad mythtv-0.22.0-fixes23003~/libs/libmythtv/mpegrecorder.cpp mythtv-0.22.0-fixes23003/libs/libmythtv/mpegrecorder.cpp
--- mythtv-0.22.0-fixes23003~/libs/libmythtv/mpegrecorder.cpp	2009-12-27 12:09:48.000000000 -0600
+++ mythtv-0.22.0-fixes23003/libs/libmythtv/mpegrecorder.cpp	2009-12-27 12:14:18.000000000 -0600
@@ -1432,12 +1432,7 @@
     {
         VERBOSE(VB_RECORD, LOC + "PauseAndWait unpause");
 
-        if (driver == "hdpvr")
-        {
-            m_h264_parser.Reset();
-            _wait_for_keyframe_option = true;
-            _seen_sps = false;
-        }
+        ResetStreamParser();
 
         // Some drivers require streaming to be disabled before
         // an input switch and other channel format setting.
@@ -1503,12 +1498,7 @@
 
     if (ioctl(fd, VIDIOC_ENCODER_CMD, &command) == 0)
     {
-        if (driver == "hdpvr")
-        {
-            m_h264_parser.Reset();
-            _wait_for_keyframe_option = true;
-            _seen_sps = false;
-        }
+        ResetStreamParser();
 
         VERBOSE(VB_RECORD, LOC + "Encoding started");
         return true;
@@ -1690,3 +1680,15 @@
         SetBitrate(bitrate, maxbitrate, "New");
     }
 }
+
+void MpegRecorder::ResetStreamParser(void)
+{
+    if (driver == "hdpvr")
+    {
+        m_h264_parser.Reset();
+        _wait_for_keyframe_option = true;
+        _seen_sps = false;
+    }
+
+    RecorderBase::ResetStreamParser();
+}
diff -urNad mythtv-0.22.0-fixes23003~/libs/libmythtv/mpegrecorder.h mythtv-0.22.0-fixes23003/libs/libmythtv/mpegrecorder.h
--- mythtv-0.22.0-fixes23003~/libs/libmythtv/mpegrecorder.h	2009-12-27 12:09:48.000000000 -0600
+++ mythtv-0.22.0-fixes23003/libs/libmythtv/mpegrecorder.h	2009-12-27 12:11:20.000000000 -0600
@@ -63,6 +63,9 @@
     // ReaderPausedCB
     virtual void ReaderPaused(int fd) { pauseWait.wakeAll(); }
 
+    // Reset stream parsers when necessary
+    virtual void ResetStreamParser(void);
+
   private:
     void SetIntOption(RecordingProfile *profile, const QString &name);
     void SetStrOption(RecordingProfile *profile, const QString &name);
diff -urNad mythtv-0.22.0-fixes23003~/libs/libmythtv/recorderbase.cpp mythtv-0.22.0-fixes23003/libs/libmythtv/recorderbase.cpp
--- mythtv-0.22.0-fixes23003~/libs/libmythtv/recorderbase.cpp	2009-10-19 01:00:11.000000000 -0500
+++ mythtv-0.22.0-fixes23003/libs/libmythtv/recorderbase.cpp	2009-12-27 12:10:35.000000000 -0600
@@ -241,6 +241,8 @@
         rb_changed = true;
 
         StartNewFile();
+
+        ResetStreamParser();
     }
     nextRingBufferLock.unlock();
 
diff -urNad mythtv-0.22.0-fixes23003~/libs/libmythtv/recorderbase.h mythtv-0.22.0-fixes23003/libs/libmythtv/recorderbase.h
--- mythtv-0.22.0-fixes23003~/libs/libmythtv/recorderbase.h	2009-10-14 20:32:51.000000000 -0500
+++ mythtv-0.22.0-fixes23003/libs/libmythtv/recorderbase.h	2009-12-27 12:11:53.000000000 -0600
@@ -213,6 +213,11 @@
      */
     virtual void CheckForRingBufferSwitch(void);
 
+    /** \brief Inherited method for the stream parser to be reset after
+               a ringbuffer change. Used mainly in mpegrecorder for H264Parser.
+     */
+    virtual void ResetStreamParser(void) { };
+
     /** \brief Save the seektable to the DB
      */
     void SavePositionMap(bool force = false);
